package com.leetcode.题库;

/**
 * @author 覃国强
 * @date 2022-02-27 20:09
 */
public class 题库_0553_最优除法 {

  static
  class Solution {
    public String optimalDivision(int[] nums) {
      if (nums.length == 1) {
        return Integer.toString(nums[0]);
      }
      StringBuilder sb = new StringBuilder(nums[0] + "/");
      if (nums.length > 2) {
        sb.append("(");
      }
      for (int i = 1; i < nums.length; ++i) {
        sb.append(nums[i]);
        if (i != nums.length - 1) {
          sb.append("/");
        }
      }
      if (nums.length > 2) {
        sb.append(")");
      }

      return sb.toString();
    }
  }

}
